feat(web): HTTP Basic Auth for the web UI#181
Merged
Conversation
When the web server is bound to a non-loopback address (e.g. 0.0.0.0 so the UI is reachable from the LAN), any browser on the same network can otherwise read and edit memories directly. This commit gates the UI on HTTP Basic Auth so the obvious threat model is closed off by default. What changed: - webServerAuthPassword / webServerAuthUsername in opencode-mem.jsonc turn the gate on. Username defaults to the current OS user; password accepts the same env:// and file:// shorthands as memoryApiKey. - src/services/web-auth.ts parses Authorization: Basic ..., compares credentials with timingSafeEqual, and serves a 401 + WWW-Authenticate challenge with Cache-Control: no-store. - src/services/cors.ts now accepts non-loopback browser origins when httpAuthEnabled is true, so once auth is on, tools hosted on other origins can talk to the API. /api/health is unauthenticated and is reused as the health probe by checkServerAvailable. - The frontend polls /api/health on load; if authEnabled is false and the page is being served from a non-loopback hostname it shows a short banner pointing at webServerAuthPassword. - Tests cover the credential check, challenge format, and the new CORS option.
Merged
Owner
|
Merged into |
GCS-ZHN
added a commit
to GCS-ZHN/opencode-mem
that referenced
this pull request
Jul 22, 2026
…client fix, and deduplicate-prompt fix alongside the merged tickernelz#178 / tickernelz#181 features
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the web UI is bound to a non-loopback address (e.g.
0.0.0.0so it is reachable from the LAN), any browser on the same network can otherwise read and edit memories directly. This PR gates the UI on HTTP Basic Auth so the obvious threat model is closed off by default.What changes:
webServerAuthPassword/webServerAuthUsernameturn the gate on. Username defaults to the current OS user; password accepts the sameenv://andfile://shorthands asmemoryApiKey.src/services/web-auth.tsparsesAuthorization: Basic …, compares credentials withtimingSafeEqual, and serves a 401 +WWW-Authenticatechallenge withCache-Control: no-store.src/services/cors.tsnow accepts non-loopback browser origins when auth is on, so tools hosted on other origins can talk to the API once they authenticate./api/healthis unauthenticated and is reused as the health probe bycheckServerAvailable./api/healthon load; ifauthEnabledis false and the page is served from a non-loopback hostname it shows a short banner pointing atwebServerAuthPassword.Notes:
upstream/mainso the diff is just the auth feature (no memory-xml-markers mix-in).